package sostats.core.datasource;

public class DataSource {
	private String host;
	private String port;
	private String userName;
	private String password;
	private String databaseName;
	private Type type;
	@Override
	public String toString(){
		StringBuilder builder = new StringBuilder();
		builder.append(type).append("://").append(host).append(":").append(port)
			.append(":").append(databaseName);
		return builder.toString();
	}
	public DataSource(){
		
	}
	public String getHost() {
		return host;
	}
	public void setHost(String host) {
		this.host = host;
	}
	public String getPort() {
		return port;
	}
	public void setPort(String port) {
		this.port = port;
	}
	public String getDatabaseName() {
		return databaseName;
	}
	public void setDatabaseName(String databaseName) {
		this.databaseName = databaseName;
	}
	public Type getType() {
		return type;
	}
	public void setType(Type type) {
		this.type = type;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getDriver(){
		return type.driver;
	}
	public String getUrl(){
		return type.urlPrefix+host+":"+port+":"+databaseName;
	}
	public String getUserName(){
		return userName;
	}
	public String getPassword(){
		return password;
	}
	
	public DataSource(String host, String port, String userName,
			String password, String databaseName,String type) {
		super();
		this.host = host;
		this.port = port;
		this.userName = userName;
		this.password = password;
		this.databaseName = databaseName;
		this.type = Type.valueOf(type);
	}
	

	public static enum Type{
		ORACLE("oracle.jdbc.driver.OracleDriver","jdbc:oracle:thin:@"),
		MYSQL("com.mysql.jdbc.Driver","jdbc:mysql://");
		private String driver;
		private String urlPrefix;
		Type(String driver,String prefix){
			this.driver = driver;
			this.urlPrefix = prefix;
		}
		public String driver(){
			return driver;
		}
		public String urlPrefix(){
			return urlPrefix;
		}
		public static Type fromString(String type){
			if(type.equals("ORACLE")) return ORACLE;
			return MYSQL;
		}
	}
}
